package com.hmall.item.interceptor;


import com.hmall.item.context.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
public class AuthorizationInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String requestHeader = request.getHeader("authorization");


        if (!requestHeader.isEmpty()) {
            Long longValue = Long.parseLong(requestHeader);
            // ... 进一步处理longValue
            BaseContext.setCurrentId(longValue);
        }


        log.info("----{}------",requestHeader);

        return true;

    }
}
